The dataset used is already clean thus no nead to deal with NA’s or other irregularities of similar nature.
Data1 <- as_tibble(Crime_Economics_data)
Data1$`Per Capita Income` <- gsub(",", " ", Data1$`Per Capita Income`)
Data1$`Population Density (per sq. km)` <- gsub(",", " ", Data1$`Population Density (per sq. km)`)
Data1$`Per Capita Income` <- gsub(" ", "", Data1$`Per Capita Income`)
Data1$`Population Density (per sq. km)` <- gsub(" ", "", Data1$`Population Density (per sq. km)`)
sapply(Data1[,-1], as.numeric)
## Crime Rate Unemployment (%) HDI Population Density (per sq. km)
## [1,] 76.31 11.2 0.51 57
## [2,] 42.53 11.3 0.80 100
## [3,] 52.03 11.5 0.75 18
## [4,] 63.82 7.0 0.85 16
## [5,] 22.79 7.7 0.78 99
## [6,] 43.03 7.1 0.94 3
## [7,] 25.54 5.7 0.92 106
## [8,] 32.02 6.0 0.76 115
## [9,] 63.90 4.2 0.63 1087
## [10,] 59.58 4.6 0.82 46
## [11,] 44.58 5.3 0.93 376
## [12,] 57.77 3.5 0.72 10
## [13,] 42.99 18.4 0.78 65
## [14,] 67.49 2.9 0.77 25
## [15,] 38.21 4.7 0.82 64
## [16,] 51.13 0.7 0.59 90
## [17,] 65.24 3.4 0.56 53
## [18,] 41.89 6.9 0.93 4
## [19,] 53.42 10.4 0.85 25
## [20,] 30.14 6.7 0.76 149
## [21,] 56.87 14.2 0.77 43
## [22,] 54.22 22.0 0.81 98
## [23,] 24.59 7.5 0.85 73
## [24,] 31.28 9.4 0.89 129
## [25,] 25.52 9.3 0.90 135
## [26,] 26.22 5.7 0.94 133
## [27,] 61.02 5.9 0.76 221
## [28,] 55.23 4.9 0.76 67
## [29,] 46.83 5.7 0.71 98
## [30,] 67.79 4.2 0.67 305
## [31,] 23.71 6.8 0.89 29
## [32,] 49.30 1.5 0.49 99
## [33,] 27.59 8.4 0.94 16
## [34,] 51.99 11.9 0.90 118
## [35,] 23.38 20.4 0.81 57
## [36,] 35.79 5.4 0.95 233
## [37,] 46.98 1.0 0.61 125
## [38,] 45.85 6.8 0.89 80
## [39,] 58.67 1.0 0.66 158
## [40,] 74.54 5.2 0.63 85
## [41,] 22.00 6.4 0.95 6677
## [42,] 34.36 4.9 0.85 104
## [43,] 23.75 7.2 0.95 3
## [44,] 44.43 7.9 0.65 411
## [45,] 45.93 7.1 0.72 140
## [46,] 49.38 11.2 0.78 50
## [47,] 48.42 12.8 0.67 88
## [48,] 45.51 1.9 0.96 69
## [49,] 31.47 2.9 0.92 431
## [50,] 44.85 10.7 0.89 201
## [51,] 67.42 7.9 0.73 267
## [52,] 22.19 1.6 0.92 337
## [53,] 39.96 14.6 0.73 112
## [54,] 53.77 5.0 0.83 7
## [55,] 60.14 2.6 0.60 87
## [56,] 56.87 6.6 0.70 32
## [57,] 38.77 8.5 0.87 30
## [58,] 46.77 6.3 0.74 656
## [59,] 61.78 18.6 0.72 4
## [60,] 33.42 9.6 0.88 43
## [61,] 34.13 2.5 0.92 234
## [62,] 57.29 4.6 0.81 95
## [63,] 55.34 6.4 0.74 1719
## [64,] 40.39 3.9 0.90 1390
## [65,] 48.88 30.0 0.80 644
## [66,] 54.19 3.8 0.78 64
## [67,] 46.35 2.0 0.75 120
## [68,] 56.01 5.9 0.74 2
## [69,] 41.18 5.6 0.83 45
## [70,] 48.66 12.7 0.69 81
## [71,] 46.51 1.7 0.58 79
## [72,] 65.21 23.0 0.65 3
## [73,] 36.01 2.6 0.60 191
## [74,] 27.16 12.8 0.94 457
## [75,] 42.88 5.3 0.93 18
## [76,] 47.89 7.4 0.66 50
## [77,] 64.06 2.7 0.54 212
## [78,] 39.12 11.2 0.77 81
## [79,] 33.72 3.5 0.96 16
## [80,] 42.51 4.4 0.56 241
## [81,] 45.15 3.8 0.82 55
## [82,] 49.37 5.7 0.73 17
## [83,] 66.72 16.4 0.78 25
## [84,] 42.46 10.0 0.72 356
## [85,] 30.50 3.1 0.88 122
## [86,] 29.91 7.2 0.86 111
## [87,] 28.30 5.7 0.83 82
## [88,] 39.99 6.3 0.82 9
## [89,] 24.89 14.0 0.54 467
## [90,] 25.23 7.5 0.85 16
## [91,] 38.10 7.3 0.81 100
## [92,] 27.96 3.6 0.94 8041
## [93,] 30.37 7.0 0.86 111
## [94,] 22.28 4.9 0.92 102
## [95,] 76.86 35.3 0.71 47
## [96,] 26.68 4.2 0.92 511
## [97,] 33.32 13.3 0.90 92
## [98,] 41.39 5.4 0.78 324
## [99,] 48.00 8.9 0.95 22
## [100,] 21.62 5.1 0.96 207
## [101,] 56.00 2.0 0.53 59
## [102,] 39.35 1.9 0.78 135
## [103,] 43.69 16.2 0.74 71
## [104,] 39.62 12.7 0.82 105
## [105,] 56.12 1.9 0.54 177
## [106,] 47.42 9.9 0.78 73
## [107,] 15.23 2.4 0.89 115
## [108,] 47.81 3.8 0.93 34
## [109,] 51.73 11.1 0.82 20
## [110,] 33.42 8.9 0.72 73
## [111,] 83.76 9.4 0.71 32
## [112,] 46.19 8.8 0.70 289
## [113,] 43.62 11.4 0.58 23
## [114,] 59.30 5.0 0.57 37
## Weapons per 100 persons Per Capita Income Gini Coefficient Literacy Rate
## [1,] 12.5 508 27.80 0.38
## [2,] 12.0 5181 33.20 0.98
## [3,] 2.1 3368 27.60 0.80
## [4,] 7.4 8476 41.40 0.98
## [5,] 6.1 4266 34.40 1.00
## [6,] 14.5 55823 34.40 0.99
## [7,] 30.0 48106 29.70 0.99
## [8,] 3.6 4202 26.60 1.00
## [9,] 0.4 2001 32.40 0.76
## [10,] 6.1 6377 25.20 1.00
## [11,] 12.7 45028 27.40 0.99
## [12,] 2.0 3133 42.20 0.96
## [13,] 31.2 6035 33.00 0.99
## [14,] 8.3 6797 53.30 0.92
## [15,] 8.4 10058 40.40 0.98
## [16,] 4.5 1513 69.20 0.77
## [17,] 2.1 1502 46.60 0.75
## [18,] 34.7 43560 33.80 0.99
## [19,] 12.1 13232 44.40 0.97
## [20,] 3.6 10229 38.50 0.96
## [21,] 10.1 5333 50.40 0.95
## [22,] 10.0 12077 48.00 0.79
## [23,] 13.7 13934 30.40 0.98
## [24,] 34.0 28133 31.40 1.00
## [25,] 12.5 22911 24.90 0.99
## [26,] 9.9 61477 28.70 0.99
## [27,] 7.4 7268 43.70 0.92
## [28,] 2.4 5600 45.40 0.68
## [29,] 4.1 3609 31.50 0.95
## [30,] 12.0 3799 38.60 0.75
## [31,] 5.0 23106 30.40 0.74
## [32,] 0.4 840 35.00 0.49
## [33,] 32.4 48685 27.40 0.99
## [34,] 19.6 38959 31.60 0.99
## [35,] 10.1 3984 36.40 1.00
## [36,] 19.6 45909 31.90 0.99
## [37,] 8.0 2206 43.50 0.77
## [38,] 17.6 18117 34.40 0.98
## [39,] 12.1 4332 48.30 0.79
## [40,] 14.1 2406 52.10 0.89
## [41,] 3.6 46611 46.70 0.99
## [42,] 10.5 16129 30.60 0.99
## [43,] 31.7 63644 26.80 0.99
## [44,] 5.3 1931 37.80 0.74
## [45,] 0.0 3870 39.00 0.94
## [46,] 7.3 11183 40.80 0.87
## [47,] 19.6 4146 29.50 0.44
## [48,] 7.2 86251 32.80 0.99
## [49,] 6.7 47034 39.00 0.97
## [50,] 14.4 31238 35.90 0.99
## [51,] 8.8 4665 45.50 0.89
## [52,] 0.3 39990 32.90 0.99
## [53,] 18.7 4283 33.70 0.98
## [54,] 2.8 9111 27.50 1.00
## [55,] 1.5 1879 40.80 0.78
## [56,] 2.8 1186 27.70 1.00
## [57,] 10.5 17871 35.60 1.00
## [58,] 31.9 9310 31.80 0.94
## [59,] 13.3 4243 69.30 0.91
## [60,] 13.6 20772 37.30 1.00
## [61,] 18.9 117182 34.90 0.99
## [62,] 0.7 10402 41.00 0.66
## [63,] 6.2 6924 31.30 0.95
## [64,] 28.3 33771 29.20 0.39
## [65,] 8.3 8587 36.80 0.91
## [66,] 12.9 8326 45.40 0.94
## [67,] 3.0 2954 25.70 0.99
## [68,] 7.9 4007 32.70 0.98
## [69,] 39.1 7626 39.00 0.99
## [70,] 4.8 3108 39.50 0.74
## [71,] 1.6 1292 30.70 0.76
## [72,] 15.4 4215 59.10 0.82
## [73,] 1.5 1135 32.80 0.65
## [74,] 2.6 53334 28.50 0.99
## [75,] 26.3 43972 32.50 0.99
## [76,] 5.2 1905 46.20 0.83
## [77,] 3.2 2085 35.10 0.60
## [78,] 29.8 5886 34.20 1.00
## [79,] 28.8 66871 27.00 0.99
## [80,] 22.3 1167 33.50 0.59
## [81,] 10.8 12269 49.20 0.95
## [82,] 16.7 4950 46.20 0.96
## [83,] 2.0 6163 42.80 0.95
## [84,] 3.6 3299 44.40 0.96
## [85,] 2.5 15764 29.70 1.00
## [86,] 21.3 22413 33.80 0.95
## [87,] 2.6 12929 36.00 0.99
## [88,] 12.3 10166 37.50 1.00
## [89,] 0.5 798 43.70 0.71
## [90,] 16.7 20110 54.10 0.95
## [91,] 39.1 7656 36.20 0.98
## [92,] 0.3 58114 0.36 0.97
## [93,] 6.5 19264 25.20 1.00
## [94,] 15.6 25777 24.20 1.00
## [95,] 9.7 5094 63.00 0.94
## [96,] 0.2 31947 31.60 0.98
## [97,] 7.5 27409 34.70 0.98
## [98,] 2.4 3768 39.80 0.93
## [99,] 23.1 53575 28.80 0.99
## [100,] 27.6 86919 32.70 0.99
## [101,] 0.8 1115 40.50 0.80
## [102,] 15.1 7189 36.40 0.97
## [103,] 1.1 3318 32.80 0.82
## [104,] 16.5 8538 41.90 0.95
## [105,] 0.8 846 42.80 0.74
## [106,] 9.9 3557 26.10 1.00
## [107,] 16.7 36285 32.50 0.94
## [108,] 120.5 63123 34.80 0.86
## [109,] 34.7 15438 41.40 0.98
## [110,] 0.4 1724 39.70 1.00
## [111,] 18.5 3740 46.90 0.95
## [112,] 1.6 2786 35.70 0.95
## [113,] 0.9 985 57.10 0.63
## [114,] 2.8 1466 44.30 0.87
## Happiness Index
## [1,] 2.52
## [2,] 5.12
## [3,] 4.89
## [4,] 5.93
## [5,] 5.28
## [6,] 7.18
## [7,] 7.27
## [8,] 5.17
## [9,] 5.03
## [10,] 5.53
## [11,] 6.83
## [12,] 5.72
## [13,] 5.81
## [14,] 6.33
## [15,] 5.27
## [16,] 4.83
## [17,] 5.14
## [18,] 7.10
## [19,] 6.17
## [20,] 5.34
## [21,] 6.01
## [22,] 7.07
## [23,] 5.88
## [24,] 6.22
## [25,] 6.97
## [26,] 7.62
## [27,] 5.55
## [28,] 5.76
## [29,] 4.28
## [30,] 6.06
## [31,] 6.19
## [32,] 4.28
## [33,] 7.84
## [34,] 6.69
## [35,] 4.89
## [36,] 7.16
## [37,] 5.09
## [38,] 5.72
## [39,] 6.44
## [40,] 5.92
## [41,] 5.48
## [42,] 5.99
## [43,] 7.55
## [44,] 3.82
## [45,] 5.35
## [46,] 4.72
## [47,] 4.85
## [48,] 7.09
## [49,] 7.16
## [50,] 6.48
## [51,] 6.31
## [52,] 5.94
## [53,] 4.40
## [54,] 6.15
## [55,] 4.61
## [56,] 5.74
## [57,] 6.03
## [58,] 4.58
## [59,] 5.41
## [60,] 6.26
## [61,] 7.32
## [62,] 5.38
## [63,] 5.20
## [64,] 6.60
## [65,] 6.05
## [66,] 6.32
## [67,] 5.77
## [68,] 5.68
## [69,] 5.58
## [70,] 4.92
## [71,] 4.43
## [72,] 4.57
## [73,] 5.27
## [74,] 7.46
## [75,] 7.28
## [76,] 5.97
## [77,] 4.76
## [78,] 5.10
## [79,] 7.39
## [80,] 4.93
## [81,] 6.18
## [82,] 5.65
## [83,] 5.84
## [84,] 5.88
## [85,] 6.17
## [86,] 5.93
## [87,] 6.14
## [88,] 5.48
## [89,] 3.42
## [90,] 6.49
## [91,] 6.08
## [92,] 6.38
## [93,] 6.33
## [94,] 6.46
## [95,] 4.96
## [96,] 5.85
## [97,] 6.49
## [98,] 4.33
## [99,] 7.36
## [100,] 7.57
## [101,] 3.62
## [102,] 5.99
## [103,] 4.60
## [104,] 4.95
## [105,] 4.64
## [106,] 4.88
## [107,] 6.56
## [108,] 6.95
## [109,] 6.43
## [110,] 6.18
## [111,] 4.89
## [112,] 5.41
## [113,] 4.07
## [114,] 3.15
Data1 <- sapply(Data1[,-1], as.numeric)
Data1 <- as_tibble(Data1)
source("Code/dens_plot.R")
dens_plot(alpha = 0.7, binwidth = 4)
source("Code/dens_plot_log.R")
dens_plot_log(alpha = 0.7, binwidth = 0.2)
The density plot is nearly normally distributed with some outliers in
the lower quantiles.
source("Code/predictor_Corr.R")
## corrplot 0.92 loaded
## Loading required package: plotly
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
## Loading required package: viridis
## Loading required package: viridisLite
##
## ======================
## Welcome to heatmaply version 1.4.2
##
## Type citation('heatmaply') for how to cite the package.
## Type ?heatmaply for the main documentation.
##
## The github page is: https://github.com/talgalili/heatmaply/
## Please submit your suggestions and bug-reports at: https://github.com/talgalili/heatmaply/issues
## You may ask questions at stackoverflow, use the r and heatmaply tags:
## https://stackoverflow.com/questions/tagged/heatmaply
## ======================
## Warning in doTryCatch(return(expr), name, parentenv, handler): unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
## dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib
## Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/modules/R_X11.so
## Reason: image not found
predictor_Corr(alpha = 0.7)